package com.jim.healio.graphrag.config;

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
@ConditionalOnProperty(prefix = "healio.graphrag", name = "enabled", havingValue = "true", matchIfMissing = true)
public class GraphRAGConfig {

    private static final Logger logger = LoggerFactory.getLogger(GraphRAGConfig.class);

    @Autowired
    private GraphRAGProperties properties;

    @Bean
    public Driver neo4jDriver() {
        logger.info("配置Neo4j驱动连接: {}", properties.getNeo4j().getUri());
        
        return GraphDatabase.driver(
            properties.getNeo4j().getUri(),
            AuthTokens.basic(
                properties.getNeo4j().getUsername(),
                properties.getNeo4j().getPassword()
            ),
            org.neo4j.driver.Config.builder()
                .withMaxConnectionPoolSize(properties.getNeo4j().getMaxConnectionPoolSize())
                .withConnectionTimeout(properties.getNeo4j().getConnectionTimeoutMs(), TimeUnit.MILLISECONDS)
                .build()
        );
    }
} 